package com.goodfather.textbook.youdao.pad.weight;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;

public class OverlayView extends FrameLayout {
    private int mShowCount = 0;
    public OverlayView(Context context) {
        super(context);
    }

    public OverlayView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setParent(ViewGroup parent) {
        if (parent != null) {
            parent.addView(this);
        }
    }

    public void show() {
        if (mShowCount == 0) {
            setVisibility(VISIBLE);
        }
        mShowCount ++;
        setVisibility(VISIBLE);
    }

    public void dismiss() {
        mShowCount --;
        if (mShowCount <= 0) {
            setVisibility(GONE);
            mShowCount = 0;
        }
        setVisibility(GONE);
    }


    public void dismissAll() {
        setVisibility(GONE);
    }

    public void remove() {
        if (getParent() != null) {
            ((ViewGroup)getParent()).removeView(this);
        }
    }
}
